﻿
using System;
using System.Collections.Generic;
using System.Xml;

namespace LExperiment.Master
{
    sealed class DaemonConfig
    {
        public string Address { get; set; }
        public int Port { get; set; }
    }

    static class DaemonConfigReader
    {
        public static void Read(IList<DaemonConfig> configCollection, string fileName)
        {
            // prepare
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;
            settings.IgnoreWhitespace = true;
            settings.IgnoreProcessingInstructions = true;

            // start reading
            using (XmlReader reader = XmlReader.Create(fileName, settings))
            {
                reader.MoveToContent();

                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.LocalName.Equals("daemon"))
                    {
                        DaemonConfig config = new DaemonConfig();
                        config.Address = reader["address"];
                        config.Port = int.Parse(reader["port"]);

                        configCollection.Add(config);
                    }
                }// while
            }
        }
    }
}